package com.org.api.admin.service.impl;

import com.github.devgcoder.locache.LoCacheEvict;
import com.github.devgcoder.locache.LoCacheable;
import com.org.api.admin.dao.TestMapper;
import com.org.api.admin.entity.vo.TestVo;
import com.org.api.admin.service.TestService;

import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;

/**
 * @author duheng
 * @Date 2021/11/20 21:01
 */
@Service
public class TestServiceImpl implements TestService {

	@Autowired
	private TestMapper testMapper;

	//	@LoCacheable(cacheNames = "cache:testVo", key = "#testVo.pid", timeout = 5, timeUnit = TimeUnit.MINUTES)
	@Override
	public List<Map<String, Object>> localList(TestVo testVo) {
		return testMapper.list(testVo);
	}

	@LoCacheable(cacheNames = "cache:testVo", key = "#testVo.pid", timeout = 5, timeUnit = TimeUnit.MINUTES, cacheThreadNumber = 5)
	@Override
	public List<Map<String, Object>> localListTempCache(TestVo testVo) {
		return testMapper.list(testVo);
	}

	@LoCacheEvict(cacheNames = "cache:testVo", key = "#testVo.pid")
	@Override
	public void deleteLocalList(TestVo testVo) {

	}

	@Cacheable(cacheNames = "cache:testVo", key = "#testVo.pid")
	@Override
	public List<Map<String, Object>> redisList(TestVo testVo) {
		return testMapper.list(testVo);
	}

	@LoCacheable(cacheNames = "cache:bigTestVo", key = "#testVo.pid", timeout = 5, timeUnit = TimeUnit.MINUTES)
	@Override
	public List<Map<String, Object>> localListBigData(TestVo testVo) {
		return testMapper.listBigData(testVo);
	}

	@LoCacheEvict(cacheNames = "cache:bigTestVo", key = "#testVo.pid")
	@Override
	public void deleteLocalListBigData(TestVo testVo) {

	}

	@Cacheable(cacheNames = "cache:bigTestVo", key = "#testVo.pid")
	@Override
	public List<Map<String, Object>> redisListBigData(TestVo testVo) {
		return testMapper.listBigData(testVo);
	}

	@Async
	@Override
	public void asyncTest() {
		try {
			Thread.sleep(10000);
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
		String s = "123456";
		System.out.println(s);
	}
}
